<?php
/**
 * Created by PhpStorm.
 * User: A
 * Date: 2016/9/21
 * Time: 16:54
 */

namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Contest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use DB;

class ContestController extends Controller
{
    public function getIndex(Request $request){
        //config('site.admin.pageSize')
        if($request->has('title')){
            $items = Contest::where('advertisement','like', '%' . $request['title'] . '%')->orderBy('vote','desc')->paginate(config('site.admin.pageSize'));
        }else{
            $items = Contest::orderBy('vote','desc')->paginate(config('site.admin.pageSize'));
        }

        return view('admin.contest.index', [
            'items' => $items,
            'appends' => $request->all()
        ]);
    }
    public function postDelete($id)
    {
        $ret = ['state' => 'fail', 'message' => '未知错误，请刷新重试'];
        if (contest::destroy($id)) {
            $ret = ['state' => 'success', 'message' => '删除成功'];
        }
        return \Response::json($ret);
    }
}